package com.hsh.utils.vo;

import io.swagger.annotations.ApiModelProperty;
import lombok.Data;

import java.util.HashMap;
import java.util.Map;

/**
 * @author 黄思海
 * @date 2021/6/26
 */
@Data
public class Result {
    public static final String MSG_SUCCESS = "success";
    public static final String MSG_FAIL = "fail";
    public static final String VERROR = "verror";
    public static final String SEARCH_LIST_RESULT = "records";

    @ApiModelProperty(value = "返回消息")
    private String msg;

    @ApiModelProperty(value = "返回数据")
    private Map<String, Object> data = new HashMap<>();

    private Result() {
    }

    public static Result fail(String error) {
        Result result = new Result();
        result.setMsg(MSG_FAIL);
        result.data.put(VERROR, error);
        return result;
    }

    public static Result fail() {
        Result result = new Result();
        result.setMsg(MSG_FAIL);
        return result;
    }


    public static Result success() {
        Result result = new Result();
        result.setMsg(MSG_SUCCESS);
        return result;
    }

    public static Result success(Object obj) {
        Result result = new Result();
        result.setMsg(MSG_SUCCESS);
        result.data.put(SEARCH_LIST_RESULT, obj);
        return result;
    }

    public Result put(String key, Object value) {
        this.data.put(key, value);
        return this;
    }

    public Result put(Map<String, Object> map) {
        this.setData(map);
        return this;
    }

}
